#include <REGX52.H>
/**
 * 灯一开始是常亮状态
 * 按一下变为熄灭状态
 * 两个状态切换
 */
void delay_ms(unsigned int ms)
{
    unsigned int i, j;
    for (i = 0; i < ms; i++)
    {
        for (j = 0; j < 123; j++)
            ;
    }
}
sbit LED = P3 ^ 1;
sbit BTN = P3 ^ 7;
void main()
{
    LED = 0;
    while (1)
    {
        if (BTN == 0)
        {
            // 防止抖动
            delay_ms(10);

            if (BTN == 0)
            {
                while (BTN == 0)
                {
                }

                // 按键被按下
                LED = ~LED;
            }
        }
    }
}